package com.tjetc.controller;

import com.tjetc.entity.Admins;
import com.tjetc.entity.Brands;
import com.tjetc.service.AdminsService;
import com.tjetc.util.R;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 后台用户表(Admins)表控制层
 *
 * @author makejava
 * @since 2025-09-15 14:10:30
 */
@RestController
@RequestMapping("admins")
public class AdminsController {
    /**
     * 服务对象
     */
    @Resource
    private AdminsService adminsService;

    /**
     * 分页查询
     *
     * @param admins 筛选条件分页对象
     * @return 查询结果
     */
    @GetMapping("queryByPage")
    public R queryByPage(Admins admins, Integer pageNum,Integer pageSize) {
        return R.ok(this.adminsService.queryByPage( pageNum,pageSize,admins));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<Admins> queryById(@PathVariable("id") Long id) {
        return ResponseEntity.ok(this.adminsService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param admins 实体
     * @return 新增结果
     */
    @PostMapping("/add")
    public R add(@RequestBody Admins admins) {
        return R.ok(adminsService.insert(admins));
    }

    @PostMapping("/update")
    public R updateById(@RequestBody Admins admins){
        this.adminsService.updateById(admins);
        return R.ok();
    }

    /**
     * 编辑数据
     *
     * @param admins 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<Admins> edit(Admins admins) {
        return ResponseEntity.ok(this.adminsService.update(admins));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @GetMapping("delete")
    public R deleteById(Long id) {
        return R.ok(this.adminsService.deleteById(id));
    }

}

